﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SnakeGame_Roman
{
   public class GameRender
    {
     //  MoveGenerator movegenerator = new MoveGenerator();

       private PieseOfSnake piese { get; set; }
        public virtual void RenderSnake(Snake snake)
        {
               Console.CursorVisible = false;

                   for (int i = snake.lenghtOfSnake - 1; i > 0; i-- )
                   {

                       snake.piesesOfSnake[i].X = snake.piesesOfSnake[i - 1].X;
                       snake.piesesOfSnake[i].Y = snake.piesesOfSnake[i - 1].Y;

                   }

                       for (int i = 0; i < snake.lenghtOfSnake; i++)
                       {
                           Console.ForegroundColor = ConsoleColor.Yellow;
                         
                           
                           this.piese = snake.piesesOfSnake[i];
                           Console.SetCursorPosition(piese.X, piese.Y);
                           Console.Write("*");
                          
                           Console.ResetColor();

                       }
                      
        }

        public void RenderFood(Food food)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.SetCursorPosition(food.x, food.y);
            Console.Write("X");
            Console.ResetColor();
        }
        
        public virtual void RenderField(GameField field)
        {
     
            Console.ForegroundColor = ConsoleColor.DarkMagenta;
            for(int i = 0; i < field.lenght; i++)
            {
                Console.SetCursorPosition(i, 0);
                Console.Write('═');
            }

            for (int i = 0; i < field.lenght; i++)
            {
                Console.SetCursorPosition(i, field.width-1);
                Console.Write('═');
            }
           
            for (int i = 0; i < field.width; i++)
            {
                Console.SetCursorPosition(0,i);
                Console.Write('║');
                
                if (i == field.width - 1)
                {
                    Console.SetCursorPosition(0, 0);
                    Console.Write('╔');
                    Console.SetCursorPosition(0,field.width-1);
                    Console.Write('╚');
                }
            }

            for (int i = 0; i < field.width; i++)
            {
                Console.SetCursorPosition(field.lenght-1, i);
                Console.Write('║');

                if (i == field.width - 1)
                {
                    Console.SetCursorPosition(field.lenght-1, 0);
                    Console.Write('╗');
                    Console.SetCursorPosition(field.lenght - 1, field.width - 1);
                    Console.Write('╝');
                }
            }

            Console.ResetColor();
           /* for (int i = 0; i < field.width; i++)
            {
                for (int j = 0; j < field.lenght; j++)
                {
                    Console.ForegroundColor = ConsoleColor.Blue;
                    if (i == 0 || i == field.width - 1) 
                    Console.Write("0");

                    else if (j == 0 || j == field.lenght - 1)
                   
                    Console.Write("0");
                     

                    else Console.Write(" ");
                    Console.ResetColor();
                }
                Console.WriteLine();

            }*/
        }
    }
 
}
